﻿using J.Status.Application.Command.BookingCommand;
using J.StatusModel;
using J.StatusModel.Dto;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using RabbitMQ;

namespace J.Status.Controllers
{
    /// <summary>
    /// 办理预定
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BookingController : ControllerBase
    {
        private readonly IMediator mediator;

        public BookingController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// (房态页面)办理入住
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddStay(StayCreateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 办理预定(添加预定表)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<int> AddBooking(BookingCreateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 添加预定和房型关系表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<int> AddBookingRoom(BookingRoomCreateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 办理保留
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> TransactionRetain(BookingRetainUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 办理维修
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> TransactionMaintain(BookingOneUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 办理脏房
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> TransactionPigsty(BookingOneUpdateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 退房
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> ReturnState(ReturnStateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 取消预订
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CancelState(CancelStateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 取消排房
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CancelTownhouse(CancelTownhouseCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 办理排房
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> TransactRoom(TransactRoomCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 返回办理排房下的房号下拉框
        /// </summary>
        /// <param name="roomNum">房号</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<List<RoomNumManage>> GetRoomNum(GetRoomNumCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 房态办理换房
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateRoomState(UpdateRoomStateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 根据房号找到该房号最近的订单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<StayDto> GetStayDto(StayDtoFindCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 所有保留信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ReserveModel>> RetainShowAll()
        {
            return await mediator.Send(new RetainSelectCommand());
        }
        /// <summary>
        /// 所有人信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<SlotDto>> SlotDtoShow(SlotDtoCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 预定表的显示
        /// </summary>
        /// <param name="command">姓名查询</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> BookingGet(BookingGetCommand command)
        {
            var res= await mediator.Send(command);
            return Ok(res);
        }
        /// <summary>
        /// 返回某房间的自定义价格
        /// </summary>
        /// <param name="roomNumber"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<object> GetPrice(GetPriceCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 办理结算
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> HandleSettlement(SettlementCreateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 结算记录
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<SettlementModel>> SettlementShow(SettlementSelectCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult SendMessage(string message)
        {
            var messageQueueManager = new MessageQueueManager("localhost", 5672, "admin", "admin", "myqueue");
            messageQueueManager.SendMessage(message);
            return Ok();
        }
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ReceiveMessage()
        {
            Task.Factory.StartNew(() =>
            {
                var messageQueueManager = new MessageQueueManager("localhost", 5672, "admin", "admin", "myqueue");
                messageQueueManager.ReceiveMessage();
            });

            return Ok("Receiving messages in the background.");
        }
        /// <summary>
        /// 预定信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<BookingModel>> BookingShow()
        {
            return await mediator.Send(new BookingSelectCommand());
        }
        /// <summary>
        /// 在住信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SlotDto>> StayShow()
        {
            return await mediator.Send(new StaySelectCommand());
        }
        /// <summary>
        /// 今日新顾客信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<BookingModel>> NewPeopleShow()
        {
            return await mediator.Send(new Booking2SelectCommand());
        }
        /// <summary>
        /// 今日在线预订信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<BookingModel>> OnLineBookingShow()
        {
            return await mediator.Send(new Booking3SelectCommand());
        }

    }
}
